package agent_store

import (
	"context"
	"xialou_platform/app/respx"
	"xialou_platform/services/agent/rpc/agentClient"

	"xialou_platform/services/agent/api/internal/svc"
	"xialou_platform/services/agent/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type StoreTypeListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewStoreTypeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) StoreTypeListLogic {
	return StoreTypeListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *StoreTypeListLogic) StoreTypeList(req *types.StoreTypeListReq) (resp []*types.StoreTypeListResp, err error) {
	typeList, err := l.svcCtx.AgentRpc.StoreTypeList(l.ctx, &agentClient.PlatformParam{Platform: req.Platform})
	if err != nil {
		return nil, err
	}
	list := make([]*types.StoreTypeListResp, 0)
	for _, storeType := range typeList.List {
		temp := &types.StoreTypeListResp{
			Id:              respx.IDFrom(storeType.StoreTypeId).ToString(),
			Name:            storeType.Name,
			IndustryLicense: storeType.IndustryLicense,
		}
		list = append(list, temp)
	}
	return list, nil
}
